﻿<UserControl x:Class="ScrumFactory.Proposals.ProposalDetail"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition" 
             xmlns:SF_DD="clr-namespace:ScrumFactory.Windows.Helpers.DragDrop;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Ext="clr-namespace:ScrumFactory.Windows.Helpers.Extensions;assembly=ScrumFactory.Windows.Helpers"
             xmlns:props="clr-namespace:ScrumFactory.Proposals.Properties"
             
             x:Name="thisView"
             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    
    <TabControl Style="{StaticResource WindowTabControl}">
        <TabControl.Items>
            <TabItem Header="{Binding PanelName}" IsSelected="{Binding IsFirstTabSelected}">
                <SF_Helpers:PanelLayout Title="{Binding PanelName}" Style="{StaticResource DetailPanelLayout}">

                    <!-- TOOLBAR -->
                    <SF_Helpers:PanelLayout.Toolbar>
                        <ToolBar Grid.Column="0">
                            <Menu>
                                <MenuItem Style="{StaticResource GoBackMenuItem}" Header="{x:Static props:Resources.Proposals_list}"/>
                                <MenuItem Header="{x:Static props:Resources.Approve}" Command="{Binding ApproveCommand}"
                                          Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}">
                                    <MenuItem.Icon>
                                        <Image Source="/Images/ToolBar/approve.png" Width="32" Height="32" Stretch="Uniform"/>
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Header="{x:Static props:Resources.Reject}" ItemsSource="{Binding Source={StaticResource RejectReasonList}}"
                                          Command="{Binding RejectCommand}"
                                          Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}">
                                    <MenuItem.ItemContainerStyle>
                                        <Style TargetType="MenuItem">
                                            <Setter Property="Template" Value="{StaticResource ToolBarMenu_SubmenuItem}"/>
                                            <Setter Property="Command" Value="{Binding ElementName=thisView, Path=Model.RejectCommand}"/>
                                            <Setter Property="CommandParameter" Value="{Binding .}"/>
                                        </Style>
                                    </MenuItem.ItemContainerStyle>
                                    <MenuItem.Icon>
                                        <Image Source="/Images/ToolBar/reject.png" Width="32" Height="32" Stretch="Uniform"/>
                                    </MenuItem.Icon>
                                    <MenuItem.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>
                                        </DataTemplate>
                                    </MenuItem.ItemTemplate>
                                </MenuItem>
                                <MenuItem Header="{x:Static props:Resources.View}" Command="{Binding ShowProposalReportCommand}">
                                    <MenuItem.Icon>
                                        <Image Source="/Images/ToolBar/preview.png" Width="32" Height="32" Stretch="Uniform"/>
                                    </MenuItem.Icon>
                                </MenuItem>
                            </Menu>

                            <ItemsControl Style="{StaticResource PluginMenuItems}" />

                        </ToolBar>                    
                    </SF_Helpers:PanelLayout.Toolbar>

                    <!-- CONTENT -->
                    <SF_Helpers:PanelLayout.Content>
                        <Grid IsEnabled="{Binding IsProposalWaiting}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="160"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            
                            <TextBlock 
                                Grid.Column="0" Grid.Row="0"
                                Text="{x:Static props:Resources.Items_price}" Style="{StaticResource LabelTextBlock}"/>
                            <TextBlock
                                Grid.Column="1" Grid.Row="0" Style="{StaticResource LabelTextBlock}">
                                <TextBlock FontSize="{StaticResource ReallyBigFontSize}" Text="{Binding Proposal.CurrencySymbol}"/>
                                <TextBlock FontSize="{StaticResource ReallyBigFontSize}" Text="{Binding ItemsPrice, StringFormat='{}{0:#,##0.00}'}"/>                                
                            </TextBlock>
                            <TextBlock 
                                Grid.Column="0" Grid.Row="1" 
                                Text="{x:Static props:Resources.Fixed_costs}" Style="{StaticResource LabelTextBlock}"/>                            
                            <TextBlock
                                Grid.Column="1" Grid.Row="1" Style="{StaticResource LabelTextBlock}">
                                <TextBlock FontSize="{StaticResource ReallyBigFontSize}" Text="{Binding Proposal.CurrencySymbol}"/>
                                <TextBlock FontSize="{StaticResource ReallyBigFontSize}" Text="{Binding FixedCostPrice, StringFormat='{}{0:#,##0.00}'}"/>                                
                            </TextBlock>
                            <TextBlock 
                                Grid.Column="0" Grid.Row="2" 
                                Text="{x:Static props:Resources.Discount}" Style="{StaticResource LabelTextBlock}"/>                            
                            <StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal">
                                <TextBox
                                    Grid.Column="1" Grid.Row="2"
                                    FontSize="{StaticResource ReallyBigFontSize}" Width="80" TextAlignment="Right"
                                    Text="{Binding Discount, StringFormat='{}{0:0.00}', UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock FontSize="{StaticResource ReallyBigFontSize}" Style="{StaticResource LabelTextBlock}">%</TextBlock>
                            </StackPanel>
                            <TextBlock 
                                Grid.Column="0" Grid.Row="3" 
                                Text="{x:Static props:Resources.Final_price}" Style="{StaticResource LabelTextBlock}"/>
                            <StackPanel Grid.Column="1" Grid.Row="3" Orientation="Horizontal">
                                <TextBox                                    
                                    FontSize="{StaticResource ReallyBigFontSize}" Width="80" MaxLength="5"
                                    Text="{Binding Proposal.CurrencySymbol}"/>
                                <TextBox
                                    IsReadOnly="{Binding UseCalcPrice}"
                                    FontSize="{StaticResource ReallyBigFontSize}" Width="250" TextAlignment="Right"
                                    Text="{Binding TotalPrice, StringFormat='{}{0:#,##0.00}'}"/>
                            </StackPanel>
                                                        
                            <CheckBox
                                Grid.Column="1" Grid.Row="4"
                                IsChecked="{Binding UseCalcPrice}"
                                Content="{x:Static props:Resources.use_calc_price}"/>
                            <TextBlock 
                                Grid.Column="0" Grid.Row="5"
                                Text="{x:Static props:Resources.Proposal}" Style="{StaticResource LabelTextBlock}"/>
                            <TextBox
                                Grid.Column="1" Grid.Row="5" HorizontalAlignment="Stretch"                                
                                Text="{Binding Proposal.ProposalName}"/>
                            <TextBlock 
                                Grid.Column="0" Grid.Row="6"
                                Text="{x:Static props:Resources.Schedule}" Style="{StaticResource LabelTextBlock}"/>
                            <StackPanel
                                Grid.Column="1" Grid.Row="6" HorizontalAlignment="Stretch" Orientation="Horizontal">
                                <DatePicker SelectedDate="{Binding EstimatedStartDate}"/>
                                <TextBlock Text="{x:Static props:Resources.to}" VerticalAlignment="Center" Foreground="Black"/>
                                <DatePicker SelectedDate="{Binding EstimatedEndDate}"/>
                                <Button Content="{x:Static props:Resources.Sync_with_sprint_dates}" Margin="20,0,0,0" Command="{Binding SyncProposalDatesCommand}" VerticalAlignment="Center" />
                            </StackPanel>
                            <TextBlock 
                                Grid.Column="0" Grid.Row="7"
                                Text="{x:Static props:Resources.Template}" Style="{StaticResource LabelTextBlock}"/>
                            <ComboBox
                                Grid.Column="1" Grid.Row="7"
                                SelectedItem="{Binding Proposal.TemplateName}"
                                ItemsSource="{Binding Templates}"/>
                            <TextBlock 
                                Grid.Column="0" Grid.Row="8" VerticalAlignment="Top"
                                Text="{x:Static props:Resources.Description}" Style="{StaticResource LabelTextBlock}"/>
                            <TextBox
                                Grid.Column="1" Grid.Row="8"
                                AcceptsReturn="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                Text="{Binding Proposal.Description}"/>
                        </Grid>
                    </SF_Helpers:PanelLayout.Content>

                </SF_Helpers:PanelLayout>
            </TabItem>
            
            <!-- ITEMS -->
            <TabItem Header="{x:Static props:Resources.Proposal_items}" Foreground="Black">
                <SF_Helpers:PanelLayout Title="{x:Static props:Resources.Proposal_items}" Style="{StaticResource DetailPanelLayout}">
                    
                    <SF_Helpers:PanelLayout.Toolbar>
                        <ToolBar>
                            <MenuItem Style="{StaticResource GoBackMenuItem}" Header="{x:Static props:Resources.Proposals_list}"/>
                            <TextBlock
                                Style="{StaticResource LabelTextBlock}"
                                FontSize="{StaticResource ReallyBigFontSize}"
                                Text="{Binding ItemsPrice, StringFormat='{}{0:C}'}"/>
                        </ToolBar>                            
                    </SF_Helpers:PanelLayout.Toolbar>
                    
                    <SF_Helpers:PanelLayout.Content>
                        
                            <ScrollViewer>
                                <ItemsControl
                                    Margin="0,15,0,0"
                                    IsEnabled="{Binding IsProposalWaiting}" VerticalAlignment="Stretch"                            
                                    ItemsSource="{Binding ProjectItems}">
                                    <ItemsControl.GroupStyle>
                                <GroupStyle>
                                    <GroupStyle.ContainerStyle>
                                        <Style TargetType="{x:Type GroupItem}">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                                        <Expander IsExpanded="True">
                                                                <Expander.Header>
                                                                    <TextBlock Text="{Binding Name}" Style="{StaticResource ItemGroupTextBlock}"/>
                                                                </Expander.Header>
                                                                    <ItemsPresenter Margin="20,0,0,0" />
                                                        </Expander>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </GroupStyle.ContainerStyle>
                                </GroupStyle>
                            </ItemsControl.GroupStyle>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <CheckBox IsChecked="{Binding IsAtProposal}">
                                                <TextBlock Foreground="Black">                                             
                                            <TextBlock Width="300" TextWrapping="Wrap">
                                                <TextBlock Text="{Binding Item.Name}" TextWrapping="Wrap"/>
                                                <TextBlock Text="{Binding Item.BacklogItemNumber, StringFormat='{}({0})'}" FontStyle="Italic" FontSize="{StaticResource SmallFontSize}" TextAlignment="Center"/>
                                            </TextBlock>
                                            <TextBlock Text="{Binding ItemPrice, StringFormat='{}{0:C}'}" Width="150" TextAlignment="Right"/>  
                                        </TextBlock>                                        
                                    </CheckBox>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>
                   
                    </SF_Helpers:PanelLayout.Content>
                </SF_Helpers:PanelLayout>                
            </TabItem>

            <!-- CLAUSES -->
            <TabItem Header="{x:Static props:Resources.Proposal_clauses}" Foreground="Black">
                <SF_Helpers:PanelLayout Title="{x:Static props:Resources.Proposal_clauses}" Style="{StaticResource DetailPanelLayout}">

                    <SF_Helpers:PanelLayout.Toolbar>
                        <ToolBar>
                            <MenuItem Style="{StaticResource GoBackMenuItem}" Header="{x:Static props:Resources.Proposals_list}"/>                            
                            <MenuItem Header="{x:Static props:Resources.New_clause}" Command="{Binding AddClauseCommand}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/ToolBar/Add.png" Width="32" Height="32" Stretch="Uniform"/>
                                </MenuItem.Icon>
                            </MenuItem>                            
                        </ToolBar>
                    </SF_Helpers:PanelLayout.Toolbar>

                    <SF_Helpers:PanelLayout.Content>
                        <ListBox
                            HorizontalAlignment="Left"
                            IsEnabled="{Binding IsProposalWaiting}"
                            ItemContainerStyle="{StaticResource NoHorizontalLineDividedListBoxItem}"
                            ScrollViewer.VerticalScrollBarVisibility="Auto"                                                        
                            Padding="10,0,40,0"
                            ItemsSource="{Binding Clauses}">                            
                            
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="auto"/>
                                        </Grid.ColumnDefinitions>
                                        <StackPanel Orientation="Vertical" Grid.Column="0">
                                            <TextBox Text="{Binding ClauseName, UpdateSourceTrigger=PropertyChanged}" Width="500"/>
                                            <TextBox Text="{Binding ClauseText, UpdateSourceTrigger=PropertyChanged}" Width="500" Height="100" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"/>
                                        </StackPanel>
                                        <DockPanel Style="{StaticResource ItemActionMenu}" Grid.Column="1"                                                   
                                                   HorizontalAlignment="Stretch" VerticalAlignment="Stretch">                                    
                                            <Button
                                                Style="{StaticResource MoveUpActionButton}" DockPanel.Dock="Top"
                                                Command="{Binding ElementName=thisView, Path=Model.MoveClauseUpCommand}"
                                                CommandParameter="{Binding}"/>
                                            <Button
                                                Style="{StaticResource MoveDownActionButton}" DockPanel.Dock="Top"
                                                Command="{Binding ElementName=thisView, Path=Model.MoveClauseDownCommand}"
                                                CommandParameter="{Binding}"/>
                                            <Button  Style="{StaticResource RemoveActionButton}" DockPanel.Dock="Bottom"
                                                      HorizontalAlignment="Right" VerticalAlignment="Bottom"
                                                Command="{Binding ElementName=thisView, Path=Model.DeleteClauseCommand}"
                                                CommandParameter="{Binding}"/>
                                        </DockPanel>
                                    </Grid>
                                    
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ListBox>
                    </SF_Helpers:PanelLayout.Content>
                </SF_Helpers:PanelLayout>
            </TabItem>

            <!-- FIXED COSTS -->
            <TabItem Header="{x:Static props:Resources.Proposal_fixed_costs}" Foreground="Black">
                <SF_Helpers:PanelLayout Title="{x:Static props:Resources.Proposal_fixed_costs}" Style="{StaticResource DetailPanelLayout}">

                    <SF_Helpers:PanelLayout.Toolbar>
                        <ToolBar>
                            <MenuItem Style="{StaticResource GoBackMenuItem}" Header="{x:Static props:Resources.Proposals_list}"/>
                            <MenuItem Header="{x:Static props:Resources.New_cost}" Command="{Binding AddCostCommand}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/ToolBar/Add.png" Width="32" Height="32" Stretch="Uniform"/>
                                </MenuItem.Icon>
                            </MenuItem>
                        </ToolBar>
                    </SF_Helpers:PanelLayout.Toolbar>

                    <SF_Helpers:PanelLayout.Content>
                        <ListView
                            HorizontalAlignment="Left"
                            IsEnabled="{Binding IsProposalWaiting}"
                           
                            ScrollViewer.VerticalScrollBarVisibility="Visible"                                                        
                            Padding="10,0,40,0"
                            ItemsSource="{Binding FixedCosts}">
                            <ListView.View>
                                <GridView>
                                    <GridViewColumn Header="{x:Static props:Resources.Cost}" Width="500">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBox Text="{Binding CostDescription}" HorizontalAlignment="Stretch"/>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Header="{x:Static props:Resources.Value}" Width="100">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBox 
                                                    SF_Comp:CommandBehavior.TheCommandToRun="{Binding ElementName=thisView, Path=Model.RefreshProposalPriceCommand}"
                                                    SF_Comp:CommandBehavior.RoutedEventName="LostFocus"
                                                    SF_Ext:TextBoxExtension.AutoSelectOnFocus="True"
                                                    Text="{Binding Cost, StringFormat='{}{0:#,##0.00}'}" HorizontalAlignment="Stretch" TextAlignment="Right"/>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Header="{x:Static props:Resources.Client_cost}" Width="80">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <CheckBox IsChecked="{Binding RepassToClient}" HorizontalAlignment="Center"/>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Width="50">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <DockPanel Style="{StaticResource ItemActionMenu}"                                                   
                                                   HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                                    <Button  Style="{StaticResource RemoveActionButton}" DockPanel.Dock="Bottom"
                                                      HorizontalAlignment="Right" VerticalAlignment="Bottom"
                                                        Command="{Binding ElementName=thisView, Path=Model.DeleteCostCommand}"
                                                        CommandParameter="{Binding}"/>
                                                </DockPanel>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>                                    
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </SF_Helpers:PanelLayout.Content>
                </SF_Helpers:PanelLayout>
            </TabItem>


        </TabControl.Items>

    </TabControl>
</UserControl>
